package wypozyczalnia.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.springframework.security.core.GrantedAuthority;


@Entity
@Table(name="authorities")
public class Authorities extends BaseEntity implements GrantedAuthority {
	
	
	private static final long serialVersionUID = 8245336150458098578L;
	
	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(updatable = false)
    private Long id=-1L;
	
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column 
	private String authority;

	public Authorities() {}
	
	public Authorities(String authority) {
		this.authority = authority;
	}
	
	public Authorities(User user,String authority) {
		super();
		this.authority=authority;
		this.username=user;
	}

	public Authorities(Long id,User user,String authority) {
		super();
		this.username=user;
		this.id=id;
		this.authority=authority;
	}

	@ManyToOne
	@JoinColumn(name="username", nullable=false)
	@OnDelete(action=OnDeleteAction.CASCADE)
	private User username;

	public User getUsername() {
		return username;
	}

	public void setUsername(User username) {
		this.username = username;
	}

	public String getAuthority() {
		return authority;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}
}
